package com.ny.shiyan.shiyan5;
import java.util.ArrayList;
import java.util.List;

public class EmployeeManager implements EmployeeOperations {
    private List<Employee> employees = new ArrayList<>();

    @Override
    public void addEmployee(Employee employee) {
        employees.add(employee);
        System.out.println("员工添加成功: " + employee.getName());
    }

    @Override
    public void updateEmployee(String name, Employee newInfo) {
        Employee found = findEmployee(name);
        if (found != null) {
            found.setName(newInfo.getName());
            found.setAge(newInfo.getAge());
            found.setSalary(newInfo.getSalary());
            System.out.println("员工信息更新成功: " + name);
        } else {
            System.out.println("未找到员工: " + name);
        }
    }

    @Override
    public void deleteEmployee(String name) {
        Employee found = findEmployee(name);
        if (found != null) {
            employees.remove(found);
            System.out.println("员工删除成功: " + name);
        } else {
            System.out.println("未找到员工: " + name);
        }
    }

    @Override
    public Employee findEmployee(String name) {
        for (Employee emp : employees) {
            if (emp.getName().equalsIgnoreCase(name)) {
                return emp;
            }
        }
        return null;
    }

    @Override
    public List<Employee> getAllEmployees() {
        return new ArrayList<>(employees);
    }
}
